<template>
    <input type="file" @change="hdlChange" />
    <button @click="hdlPause">暂停</button>
    <button @click="hdlContinue">继续</button>
    <button @click="hdlContinueUpload">断点继续</button>

    <textarea id="" cols="30" rows="10"></textarea>
    <!-- <a-upload
        name="file"
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        @change="handleChange"
        :directory="true"
    >
        <a-button>
            <upload-outlined></upload-outlined>
            Click to Upload
        </a-button>
    </a-upload> -->

    <a-upload-dragger
        v-model:fileList="fileList"
        name="file"
        :multiple="true"
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        @change="handleChange"
        @drop="handleDrop"
        class="file-dragger"
    >
        <p class="ant-upload-drag-icon">
            <inbox-outlined></inbox-outlined>
        </p>
        <p class="ant-upload-text">Click or drag file to this area to upload</p>
        <p class="ant-upload-hint">
            Support for a single or bulk upload. Strictly prohibit from
            uploading company data or other band files
        </p>
    </a-upload-dragger>
</template>

<script lang="ts" setup>
    import { UploadChangeParam } from "ant-design-vue";
    import md5 from "md5";
    import CustomSliceFileUpload from "@/utils/customSliceFileUpload";

    const onProgress = (data: any) => {
        console.log(data);
    };
    let up: any;
    const hdlChange = async (e: any) => {
        let file = e.target.files[0];

        up = new CustomSliceFileUpload(file);
        up.start({ onProgress });
        // console.log(window.preload);
        // let res = await window.preload.stat(file.path);
        // console.log(res);
    };
    const hdlPause = async () => {
        up.stop();
    };
    const hdlContinue = async () => {
        up.resume();
    };

    const handleChange = (info: UploadChangeParam) => {
        console.log(info);
    };

    const hdlContinueUpload = () => {
        let str = localStorage.getItem("uploadingFileQueue");
        if (str) {
            let arr = JSON.parse(str);
            up = new CustomSliceFileUpload(arr[0]);
            up.start({ onProgress });
        }
    };
    const fileList = ref([]);
    function handleDrop(e: DragEvent) {
        console.log(e);
    }
</script>

<style lang="scss" scoped src="./Index.scss"></style>
